package com.yichat.micro.msghttpservice.common.result;

import com.yichat.micro.msghttpservice.common.Constants;
import com.yichat.micro.msghttpservice.core.retry.RetryMsgHttpRequestVo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.regex.Pattern;

/**
 * Created by chenmohan on 2019/03/28
 *
 * @description
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class HttpResult {

    protected static final Pattern p = Pattern.compile("\\s*|\t|\r|\n");

    protected int code;

    protected String msg;

    protected String data;

    protected String buz;

    protected Long id;

    private static int HTTP_OK = 200;

    public static HttpResult ok(String msg, String data) {
        return new HttpResult(HTTP_OK, msg, data);
    }

    public static HttpResult ok(String data) {
        return new HttpResult(HTTP_OK, null, data);
    }

    public static HttpResult ok() {
        return new HttpResult(HTTP_OK, null, null);
    }

    public static HttpResult fail(int code, String msg, String data) {
        return new HttpResult(code, msg, data);
    }

    public HttpResult(int code, String msg, String data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static HttpResult ok(String msg, String data, String buz, Long id) {
        return new HttpResult(HTTP_OK, msg, data, buz, id);
    }

    public static HttpResult syncCommit(RetryMsgHttpRequestVo retryVo) {
        return new HttpResult(Constants.stauts_async, Constants.msg_status_async, null, retryVo.getVo().getBuz(), retryVo.getSid());
    }

    public static HttpResult timeout(RetryMsgHttpRequestVo retryVo) {
        return new HttpResult(Constants.status_timeout, Constants.msg_status_timeout, null, retryVo.getVo().getBuz(), retryVo.getSid());
    }

    public static HttpResult callBack(RetryMsgHttpRequestVo retryVo) {
        return new HttpResult(Constants.stauts_callback_success, Constants.msg_stauts_callback_success, null, retryVo.getVo().getBuz(), retryVo.getSid());
    }
}
